package test0103.test02;

// Java类之间的关联关系：一对一、一对多、多对一、多对多
// 单向关联
// 双向关联

public class CompanyMS {

    public static void main(String[] args) {

        // 公司(开发部(初级开发(张三、李四)、中级开发)、测试部)

        // (1)创建公司
        Company company = new Company("小米");

        // (2)创建部门和职位
        Department devDepartment = new Department(1, "开发部");
        Department testDepartment = new Department(2, "测试部");

        Position juniorDev = new Position(1, "初级开发");
        Position midDev = new Position(2, "中级开发");

        // (3)添加职位到部门
        devDepartment.addPosition(juniorDev);
        devDepartment.addPosition(midDev);

        // (4)添加部门到公司
        company.addDepartment(devDepartment);
        company.addDepartment(testDepartment);

        // (5)创建员工并添加到职位
        Employee zhangSan = new Employee(1, "张三", "男");
        Employee liSi = new Employee(2, "李四", "男");

        juniorDev.addEmployee(zhangSan);
        juniorDev.addEmployee(liSi);

        // 测试：公司、部门、职位、员工
        // test02练习题中的代码：项目中没有：SQL语句！！！！
        Department[] arr = company.getArr();
        for (Department d:arr) {
            if (d.getName() == "开发部") {
                Position[] brr = d.getArr();
                for (Position p:brr) {
                    if (p.getName() == "初级开发") {
                        Employee[] crr = p.getArr();
                        for (Employee e:crr) {
                            System.out.println(e);
                        }
                    }
                }
            }
        }


//        // (6)根据部门名查询一个部门对象
//        Department x = company.getDepartmentByName("开发部");
//        System.out.println(x);
//
//        // (7)根据职位名查询一个职位对象
//        Position y = company.getPositionByName("初级开发");
//        System.out.println(y);
//
//        // (8)根据员工名查询一个员工对象
//        Employee z = company.getEmployeeByName("张三");
//        System.out.println(z);

    }
}